package top.resty.erp.dao;

import org.apache.ibatis.annotations.*;
import top.resty.erp.domain.Manager;

import java.util.List;

@Mapper
public interface IManager {
	
	@Select("select id,real_name as realName,user_name as userName,password,telephone,role from tb_manager where " + "user_name = #{userName} and " + "password " + "= #{password}")
	public Manager getUserForNameAndPassword(Manager manager);
	
	/**
	 * 别名方式解决 数据库中带 _ 和实体类中大写字母 问题
	 */
	@Select("select id,real_name as realName,user_name as userName,password,telephone,role from tb_manager")
	public List<Manager> getManagers();
	
	@Insert("insert into tb_manager values(null,#{realName},#{userName},#{password},#{telephone},#{role})")
	public int saveManager(Manager manager);
	
	@Delete("delete from tb_manager where id = #{index}")
	public int delManager(Integer index);
	
	@Select("select count(user_name) from tb_manager where user_name = #{userName}")
	public int getName(String userName);
	
	
	/**
	 * ${arg0} = #{arg1}   解析时$不包含'' 而#包含''  代表是数值
	 **/
	@Update("update tb_manager set ${arg0} = #{arg1} where id = #{arg2}")
	public int updateManager(String keyStr, String valueStr, Integer id);
	
	@Select("select id,real_name realName , user_name as userName ,password , telephone from tb_manager where real_name = #{realName}")
	Manager findManagerByRealName(String realName);
}
